<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>ES入门 - 基本使用：索引和文档 | java知识体系</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/lm_blog_vdoing/img/favicon.ico">
    <meta name="description" content="lm_blog">
    <meta name="author" content="小猫爱吃鱼">
    <meta name="keywords" content="小猫爱吃鱼|java开发学习">
    <link rel="preload" href="/lm_blog_vdoing/assets/css/0.styles.6837ef6d.css" as="style"><link rel="preload" href="/lm_blog_vdoing/assets/js/app.fa0e5fdd.js" as="script"><link rel="preload" href="/lm_blog_vdoing/assets/js/2.d9c93b35.js" as="script"><link rel="preload" href="/lm_blog_vdoing/assets/js/24.1688627c.js" as="script"><link rel="preload" href="/lm_blog_vdoing/assets/js/5.e0bc0396.js" as="script"><link rel="preload" href="/lm_blog_vdoing/assets/js/13.ee87d1ca.js" as="script"><link rel="preload" href="/lm_blog_vdoing/assets/js/14.9d4d9cf6.js" as="script"><link rel="preload" href="/lm_blog_vdoing/assets/js/9.fc3a629f.js" as="script"><link rel="preload" href="/lm_blog_vdoing/assets/js/10.4c34cde9.js" as="script"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/11.bccd7768.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/12.e841fec0.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/15.ea506303.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/16.2da770e9.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/17.2e0242dc.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/18.304c9e7d.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/19.4b93faf0.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/20.87daf9d0.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/21.058f688b.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/22.9937ce9d.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/23.87e8eccb.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/25.04906008.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/26.494f706b.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/27.01c810da.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/28.9fbe8e29.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/29.3a1e938a.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/3.80bae7d2.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/30.4adb3ea1.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/31.5001aed0.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/32.306c6420.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/33.5fcce29f.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/34.2de40b8f.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/4.d2df651a.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/6.cbc45c4c.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/7.fd589d8e.js"><link rel="prefetch" href="/lm_blog_vdoing/assets/js/8.35156f8e.js">
    <link rel="stylesheet" href="/lm_blog_vdoing/assets/css/0.styles.6837ef6d.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/lm_blog_vdoing/" class="home-link router-link-active"><!----> <span class="site-name">java知识体系</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/lm_blog_vdoing/" class="nav-link">首页​</a></div><div class="nav-item"><a href="/lm_blog_vdoing/pages/f6054a/" class="nav-link">❁导航​</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="计算机核心" class="dropdown-title"><!----> <span class="title" style="display:;">计算机核心</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/db72cf/" class="nav-link">数据结构</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/39e2a1/" class="nav-link">计算机网络</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java" class="dropdown-title"><!----> <span class="title" style="display:;">Java</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>Java基础</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e05ef5/" class="nav-link">JavaSE</a></li></ul></li><li class="dropdown-item"><h4>JavaWeb</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/5cda88/" class="nav-link">HTML</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/cea341/" class="nav-link">CSS</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/d893c0/" class="nav-link">JavaScript</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/8f83ba/" class="nav-link">Servlet</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/8bc1c4/" class="nav-link">MVC</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/f883e2/" class="nav-link">filter|listener</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Spring生态" class="dropdown-title"><!----> <span class="title" style="display:;">Spring生态</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/462a90/" class="nav-link">Spring5</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/2e990c/" class="nav-link">SpringMVC</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/0d4af0/" class="nav-link">SpringBoot2</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/870083/" class="nav-link">SpringCloud</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/66babb/" class="nav-link">SpringSecurity</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><!----> <span class="title" style="display:;">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>消息队列</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e645d9/" class="nav-link">RabbitMQ</a></li></ul></li><li class="dropdown-item"><h4>服务器</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/9551ee/" class="nav-link">Nginx🌐</a></li></ul></li><li class="dropdown-item"><h4>服务框架</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/48771f/" class="nav-link">Dubbo</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="大数据" class="dropdown-title"><!----> <span class="title" style="display:;">大数据</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>Python</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/b9268d/" class="nav-link">Python基础</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e0bd06/" class="nav-link">数据分析</a></li></ul></li><li class="dropdown-item"><h4>环境搭建</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/600247/" class="nav-link">Hadoop集群</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/cdeb68/" class="nav-link">KVM虚拟化技术</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据库" class="dropdown-title"><!----> <span class="title" style="display:;">数据库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>SQL 数据库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e72480/" class="nav-link">MySQL</a></li></ul></li><li class="dropdown-item"><h4>NoSQL 数据库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e9cc9f/" class="nav-link">Redis</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/91197c/" class="nav-link">MongoDB</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/7b46ed/" class="nav-link">ElasticSearch</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="工具" class="dropdown-title"><!----> <span class="title" style="display:;">工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>部署</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/99e9dc/" class="nav-link">Linux</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/90cc29/" class="nav-link">Docker</a></li></ul></li><li class="dropdown-item"><h4>管理</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/45eca1/" class="nav-link">Maven</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/34892c/" class="nav-link">Git</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="面试" class="dropdown-title"><!----> <span class="title" style="display:;">面试</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/eab19d/" class="nav-link">十大排序算法</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/40ee62/" class="nav-link">力扣算法题</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/39558d/" class="nav-link">初级开发篇</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/47c622/" class="nav-link">中高进阶篇</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><!----> <span class="title" style="display:;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/myfriends/" class="nav-link">友情链接</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="本站" class="dropdown-title"><!----> <span class="title" style="display:;">本站</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>索引</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/categories/" class="nav-link">分类</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/tags/" class="nav-link">标签</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/archives/" class="nav-link">归档</a></li></ul></li><li class="dropdown-item"><h4>其他</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/9013e4/" class="nav-link">关于</a></li></ul></li></ul></div></div> <a href="https://gitee.com/lmgghub/lm_blog" target="_blank" rel="noopener noreferrer" class="repo-link">
    查看源码
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.staticaly.com/gh/xustudyxu/image-hosting@master/20220627/mmexport1656324824543.124zxwkqyzlc.webp"> <div class="blogger-info"><h3>lm_blog</h3> <span>持续学习!</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/lm_blog_vdoing/" class="nav-link">首页​</a></div><div class="nav-item"><a href="/lm_blog_vdoing/pages/f6054a/" class="nav-link">❁导航​</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="计算机核心" class="dropdown-title"><!----> <span class="title" style="display:;">计算机核心</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/db72cf/" class="nav-link">数据结构</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/39e2a1/" class="nav-link">计算机网络</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java" class="dropdown-title"><!----> <span class="title" style="display:;">Java</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>Java基础</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e05ef5/" class="nav-link">JavaSE</a></li></ul></li><li class="dropdown-item"><h4>JavaWeb</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/5cda88/" class="nav-link">HTML</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/cea341/" class="nav-link">CSS</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/d893c0/" class="nav-link">JavaScript</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/8f83ba/" class="nav-link">Servlet</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/8bc1c4/" class="nav-link">MVC</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/f883e2/" class="nav-link">filter|listener</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Spring生态" class="dropdown-title"><!----> <span class="title" style="display:;">Spring生态</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/462a90/" class="nav-link">Spring5</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/2e990c/" class="nav-link">SpringMVC</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/0d4af0/" class="nav-link">SpringBoot2</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/870083/" class="nav-link">SpringCloud</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/66babb/" class="nav-link">SpringSecurity</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><!----> <span class="title" style="display:;">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>消息队列</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e645d9/" class="nav-link">RabbitMQ</a></li></ul></li><li class="dropdown-item"><h4>服务器</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/9551ee/" class="nav-link">Nginx🌐</a></li></ul></li><li class="dropdown-item"><h4>服务框架</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/48771f/" class="nav-link">Dubbo</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="大数据" class="dropdown-title"><!----> <span class="title" style="display:;">大数据</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>Python</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/b9268d/" class="nav-link">Python基础</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e0bd06/" class="nav-link">数据分析</a></li></ul></li><li class="dropdown-item"><h4>环境搭建</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/600247/" class="nav-link">Hadoop集群</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/cdeb68/" class="nav-link">KVM虚拟化技术</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据库" class="dropdown-title"><!----> <span class="title" style="display:;">数据库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>SQL 数据库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e72480/" class="nav-link">MySQL</a></li></ul></li><li class="dropdown-item"><h4>NoSQL 数据库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/e9cc9f/" class="nav-link">Redis</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/91197c/" class="nav-link">MongoDB</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/7b46ed/" class="nav-link">ElasticSearch</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="工具" class="dropdown-title"><!----> <span class="title" style="display:;">工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>部署</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/99e9dc/" class="nav-link">Linux</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/90cc29/" class="nav-link">Docker</a></li></ul></li><li class="dropdown-item"><h4>管理</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/45eca1/" class="nav-link">Maven</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/34892c/" class="nav-link">Git</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="面试" class="dropdown-title"><!----> <span class="title" style="display:;">面试</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/eab19d/" class="nav-link">十大排序算法</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/40ee62/" class="nav-link">力扣算法题</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/39558d/" class="nav-link">初级开发篇</a></li><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/47c622/" class="nav-link">中高进阶篇</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><!----> <span class="title" style="display:;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/lm_blog_vdoing/pages/myfriends/" class="nav-link">友情链接</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="本站" class="dropdown-title"><!----> <span class="title" style="display:;">本站</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>索引</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/categories/" class="nav-link">分类</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/tags/" class="nav-link">标签</a></li><li class="dropdown-subitem"><a href="/lm_blog_vdoing/archives/" class="nav-link">归档</a></li></ul></li><li class="dropdown-item"><h4>其他</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/lm_blog_vdoing/pages/9013e4/" class="nav-link">关于</a></li></ul></li></ul></div></div> <a href="https://gitee.com/lmgghub/lm_blog" target="_blank" rel="noopener noreferrer" class="repo-link">
    查看源码
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>MySQL - 基础</span> <!----></p> <!----></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>MySQL - 进阶</span> <!----></p> <!----></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>MySQL - 运维部署</span> <!----></p> <!----></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>NoSQL - Redis</span> <!----></p> <!----></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>NoSQL - MongoDB</span> <!----></p> <!----></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>NoSQL - ElasticSearch</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/lm_blog_vdoing/pages/7b46ed/" class="sidebar-link">ElasticeSarch的概述</a></li><li><a href="/lm_blog_vdoing/pages/596552/" class="sidebar-link">ES入门 - 环境安装</a></li><li><a href="/lm_blog_vdoing/pages/bc6018/" aria-current="page" class="active sidebar-link">ES入门 - 基本使用：索引和文档</a></li><li><a href="/lm_blog_vdoing/pages/6e6e0c/" class="sidebar-link">ES入门 - 分片和副本</a></li><li><a href="/lm_blog_vdoing/pages/3d97b1/" class="sidebar-link">ES入门 - 分析器</a></li><li><a href="/lm_blog_vdoing/pages/b54e3a/" class="sidebar-link">ES入门 - java整合</a></li><li><a href="/lm_blog_vdoing/pages/7e4dff/" class="sidebar-link">ES进阶 - 分片操作原理</a></li><li><a href="/lm_blog_vdoing/pages/b82771/" class="sidebar-link">ES进阶 - 并发问题</a></li><li><a href="/lm_blog_vdoing/pages/c3becc/" class="sidebar-link">ES进阶 - 集群搭建</a></li><li><a href="/lm_blog_vdoing/pages/6d9622/" class="sidebar-link">ES进阶 - 优化配置</a></li><li><a href="/lm_blog_vdoing/pages/da009f/" class="sidebar-link">ES进阶 - 框架整合</a></li><li><a href="/lm_blog_vdoing/pages/7cb809/" class="sidebar-link">ElasticSearch面试题</a></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-1baff76c><div class="articleInfo" data-v-1baff76c><ul class="breadcrumbs" data-v-1baff76c><li data-v-1baff76c><a href="/lm_blog_vdoing/" title="首页" class="iconfont icon-home router-link-active" data-v-1baff76c></a></li> <li data-v-1baff76c><a href="/lm_blog_vdoing/categories/?category=notes" title="分类" data-v-1baff76c>notes</a></li><li data-v-1baff76c><a href="/lm_blog_vdoing/categories/?category=database" title="分类" data-v-1baff76c>database</a></li><li data-v-1baff76c><a href="/lm_blog_vdoing/categories/?category=elasticSearch" title="分类" data-v-1baff76c>elasticSearch</a></li></ul> <div class="info" data-v-1baff76c><div title="作者" class="author iconfont icon-touxiang" data-v-1baff76c><a href="javascript:;" data-v-1baff76c>lm</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-1baff76c><a href="javascript:;" data-v-1baff76c>2023-02-16</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">ES入门 - 基本使用：索引和文档<!----></h1> <!----> <div class="theme-vdoing-content content__default"><h1 id="es入门-基本使用-索引和文档"><a href="#es入门-基本使用-索引和文档" class="header-anchor">#</a> ES入门 - 基本使用：索引和文档</h1> <h2 id="restful"><a href="#restful" class="header-anchor">#</a> RESTful</h2> <p>REST 指的是一组架构约束条件和原则。满足这些约束条件和原则的应用程序或设计就是 RESTful。Web 应用程序最重要的 REST 原则是，客户端和服务器之间的交互在请求之间是无状态的。从客户端到服务器的每个请求都必须包含理解请求所必需的信息。如果服务器在请求之间的任何时间点重启，客户端不会得到通知。此外，无状态请求可以由任何可用服务器回答，这十分适合云计算之类的环境。客户端可以缓存数据以改进性能。</p> <p>在服务器端，应用程序状态和功能可以分为各种资源。资源是一个有趣的概念实体，它向客户端公开。资源的例子有：应用程序对象、数据库记录、算法等等。每个资源都使用 URI (Universal Resource Identifier) 得到一个唯一的地址。所有资源都共享统一的接口，以便在客户端和服务器之间传输状态。使用的是标准的 HTTP 方法，比如 GET、PUT、POST 和DELETE。</p> <p>在 REST 样式的 Web 服务中，每个资源都有一个地址。资源本身都是方法调用的目标，方法列表对所有资源都是一样的。这些方法都是标准方法，包括 HTTP GET、POST、PUT、DELETE，还可能包括 HEAD 和 OPTIONS。简单的理解就是，如果想要访问互联网上的资源，就必须向资源所在的服务器发出请求，请求体中必须包含资源的网络路径，以及对资源进行的操作(增删改查)。</p> <h2 id="es数据格式"><a href="#es数据格式" class="header-anchor">#</a> ES数据格式</h2> <p>ElasticSearch 是面向文档型数据库，一条数据在这里就是一个文档。为了方便大家理解，我们将 ElasticSearch 里存储文档数据和关系型数据库 MySQL 存储数据的概念进行一个类比ES 里的 Index 可以看做一个库，而 Types 相当于表，Documents 则相当于表的行。</p> <p><img alt="image" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es001.webp" loading="lazy" class="lazy"></p> <p>这里 Types 的概念已经被逐渐弱化，ElasticSearch 6.X 中，一个 index 下已经只能包含一个type，ElasticSearch 7.X 中, Type 的概念已经被删除了。</p> <p>用 JSON 作为文档序列化的格式，比如一条用户信息：</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
    <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;lm&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;sex&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;man&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;age&quot;</span> <span class="token operator">:</span> <span class="token number">25</span><span class="token punctuation">,</span>
    <span class="token property">&quot;birthDate&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1997/01/01&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;about&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;hello world&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;interests&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token string">&quot;sports&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;music&quot;</span> <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="es入门-索引"><a href="#es入门-索引" class="header-anchor">#</a> ES入门 - 索引</h2> <h3 id="索引操作"><a href="#索引操作" class="header-anchor">#</a> 索引操作</h3> <blockquote><p>对比关系型数据库，es索引（index）相关于关系型数据库（database）</p></blockquote> <h4 id="创建索引-put"><a href="#创建索引-put" class="header-anchor">#</a> 创建索引 - PUT</h4> <ul><li>使用Kibana的dev tool执行创建索引命令</li></ul> <p><img alt="es_014" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_014.jpg" loading="lazy" class="lazy"></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
 <span class="token property">&quot;acknowledged&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> 【响应结果】
 <span class="token property">&quot;shards_acknowledged&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> 【分片结果】
 <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token string">&quot;teacher&quot;</span> 【索引名称】
<span class="token punctuation">}</span>
# 注意：创建索引库的分片数默认 <span class="token number">1</span> 片，在 <span class="token number">7.0</span>.<span class="token number">0</span> 之前的 ElasticSearch 版本中，默认 <span class="token number">5</span> 片
# 若重复创建索引，则会返回错误信息
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h4 id="查看索引-get"><a href="#查看索引-get" class="header-anchor">#</a> 查看索引 - GET</h4> <ul><li>查看当前创建teacher索引信息</li></ul> <p><img alt="es_015" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_015.jpg" loading="lazy" class="lazy"></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
 	<span class="token property">&quot;teacher&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>  【索引名】
 		<span class="token property">&quot;aliases&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> 【别名】
 		<span class="token property">&quot;mappings&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> 【映射】
 		<span class="token property">&quot;settings&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
			 <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
 				<span class="token property">&quot;creation_date&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1676474076249&quot;</span><span class="token punctuation">,</span> 【创建时间】
 				<span class="token property">&quot;number_of_shards&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1&quot;</span><span class="token punctuation">,</span> 【主分片数量】
 				<span class="token property">&quot;number_of_replicas&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1&quot;</span><span class="token punctuation">,</span> 【副分片数量】
				 <span class="token property">&quot;uuid&quot;</span><span class="token operator">:</span> <span class="token string">&quot;_LMQqmh0Rd6WXpOKA&quot;</span><span class="token punctuation">,</span>【唯一标识】
 				<span class="token property">&quot;version&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span> 【版本】
					 <span class="token property">&quot;created&quot;</span><span class="token operator">:</span> <span class="token string">&quot;7080099&quot;</span>
				 <span class="token punctuation">}</span><span class="token punctuation">,</span>
 				<span class="token property">&quot;provided_name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;teacher&quot;</span>【名称】
 			<span class="token punctuation">}</span>
 		<span class="token punctuation">}</span>
 	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><ul><li>查看全部索引信息</li></ul> <p><img alt="es_016" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_016.jpg" loading="lazy" class="lazy"></p> <table><thead><tr><th>表头</th> <th>含义</th></tr></thead> <tbody><tr><td>health</td> <td>当前服务器健康状态：green(集群完整) yellow(单点正常、集群不完整) red(单点不正常)</td></tr> <tr><td>status</td> <td>索引打开、关闭状态</td></tr> <tr><td>index</td> <td>索引名</td></tr> <tr><td>uuid</td> <td>索引统一编号</td></tr> <tr><td>pri</td> <td>主分片数量</td></tr> <tr><td>rep</td> <td>副本数量</td></tr> <tr><td>docs.count</td> <td>可用文档数量</td></tr> <tr><td>docs.deleted</td> <td>文档删除状态（逻辑删除）</td></tr> <tr><td>store.size</td> <td>主分片和副分片整体占空间大小</td></tr> <tr><td>pri.store.size</td> <td>主分片占空间大小</td></tr></tbody></table> <h4 id="删除索引-delete"><a href="#删除索引-delete" class="header-anchor">#</a> 删除索引  - DELETE</h4> <ul><li>执行删除命令删除索引</li></ul> <p><img alt="es_017" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_017.jpg" loading="lazy" class="lazy"></p> <ul><li>重新查询索引是否存在</li></ul> <p><img alt="es_018" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_018.jpg" loading="lazy" class="lazy"></p> <h4 id="修改索引"><a href="#修改索引" class="header-anchor">#</a> 修改索引</h4> <p>​	将索引<strong>teacher</strong>改为索引<strong>teacher_now</strong></p> <ol><li>新建索引</li></ol> <p><img alt="es_019" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_019.png" loading="lazy" class="lazy"></p> <ol start="2"><li>复制数据</li></ol> <p><img alt="es_020" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_020.jpg" loading="lazy" class="lazy"></p> <ol start="3"><li>查询确认复制数据是否正确</li></ol> <p><img alt="es_021" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_021.jpg" loading="lazy" class="lazy"></p> <ol start="4"><li>删除旧索引</li></ol> <p><img alt="es_017" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_017.jpg" loading="lazy" class="lazy"></p> <ol start="5"><li>创建别名</li></ol> <p><img alt="es_022" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_022.jpg" loading="lazy" class="lazy"></p> <h2 id="es入门-文档"><a href="#es入门-文档" class="header-anchor">#</a> ES入门 - 文档</h2> <h3 id="文档操作"><a href="#文档操作" class="header-anchor">#</a> 文档操作</h3> <blockquote><p>对比关系型数据库，文档类比与关系型数据库表里面的数据行</p></blockquote> <h4 id="创建文档-post"><a href="#创建文档-post" class="header-anchor">#</a> 创建文档 - POST</h4> <ul><li>在teacher索引下创建文档</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code># index(索引)/type(类型)/id(唯一标识)
POST /teacher/_doc/<span class="token number">1</span>  
<span class="token punctuation">{</span>
  <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;zs&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;age&quot;</span> <span class="token operator">:</span> <span class="token number">18</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><img alt="es_023" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_023.jpg" loading="lazy" class="lazy"></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
 	<span class="token property">&quot;_index&quot;</span><span class="token operator">:</span> <span class="token string">&quot;teacher&quot;</span><span class="token punctuation">,</span>【索引】
 	<span class="token property">&quot;_type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;_doc&quot;</span><span class="token punctuation">,</span>【文档】
	<span class="token property">&quot;_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1&quot;</span><span class="token punctuation">,</span> 【唯一标识】
	<span class="token property">&quot;_version&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>【版本】
 	<span class="token property">&quot;result&quot;</span><span class="token operator">:</span> <span class="token string">&quot;created&quot;</span><span class="token punctuation">,</span> 【结果】
 	<span class="token property">&quot;_shards&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span> 【分片】
 		<span class="token property">&quot;total&quot;</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> 【分片 - 总数】
 		<span class="token property">&quot;successful&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> 【分片 - 成功】
 		<span class="token property">&quot;failed&quot;</span><span class="token operator">:</span> <span class="token number">0</span> 【分片 - 失败】
 	<span class="token punctuation">}</span><span class="token punctuation">,</span>
 	<span class="token property">&quot;_seq_no&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> 【累加版本，高并发情况下，控制es的修改，采用乐观锁机制】
 	<span class="token property">&quot;_primary_term&quot;</span><span class="token operator">:</span> <span class="token number">2</span> 【文档所在的位置，当Primary Shard发生重新分配时，该值会递增】
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><h4 id="查看文档-get"><a href="#查看文档-get" class="header-anchor">#</a> 查看文档 - GET</h4> <ul><li>查看当前创建文档</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_doc/<span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><img alt="es_024" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_024.jpg" loading="lazy" class="lazy"></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
  <span class="token property">&quot;_index&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;teacher&quot;</span><span class="token punctuation">,</span> 【索引】
  <span class="token property">&quot;_type&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;_doc&quot;</span><span class="token punctuation">,</span> 【文档】
  <span class="token property">&quot;_id&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;1&quot;</span><span class="token punctuation">,</span> 【唯一标识】
  <span class="token property">&quot;_version&quot;</span> <span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> 【版本】
  <span class="token property">&quot;_seq_no&quot;</span> <span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span> 【累加版本，高并发情况下，控制es的修改，采用乐观锁机制】
  <span class="token property">&quot;_primary_term&quot;</span> <span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> 【文档所在位置】
  <span class="token property">&quot;found&quot;</span> <span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> 【查询结果，表示是否找到】
  <span class="token property">&quot;_source&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span> 【结果】
    <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;zs&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;age&quot;</span> <span class="token operator">:</span> <span class="token number">18</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h4 id="修改文档-post"><a href="#修改文档-post" class="header-anchor">#</a> 修改文档 - POST</h4> <ul><li>覆盖修改</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>POST /teacher/_doc/<span class="token number">1</span>
<span class="token punctuation">{</span>
  <span class="token property">&quot;name&quot;</span> <span class="token operator">:</span> <span class="token string">&quot;ls&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;age&quot;</span> <span class="token operator">:</span> <span class="token number">19</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><img alt="es_025" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_025.jpg" loading="lazy" class="lazy"></p> <p><img alt="es_026" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_026.jpg" loading="lazy" class="lazy"></p> <ul><li>局部修改</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>POST /teacher/_update/<span class="token number">1</span>
<span class="token punctuation">{</span>
  <span class="token property">&quot;doc&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ww&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><img alt="es_027" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_027.jpg" loading="lazy" class="lazy"></p> <p><img alt="es_028" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_028.jpg" loading="lazy" class="lazy"></p> <h4 id="删除文档-delete"><a href="#删除文档-delete" class="header-anchor">#</a> 删除文档 - DELETE</h4> <ul><li>es删除文档，采用的是逻辑删除</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>DELETE /teacher/_doc/<span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><img alt="es_029" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_029.jpg" loading="lazy" class="lazy"></p> <ul><li>条件删除文档</li></ul> <p>新增两个文档如下</p> <p><img alt="image-20230216103143506" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_031.png" loading="lazy" class="lazy"></p> <p><img alt="es_030" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_030.jpg" loading="lazy" class="lazy"></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code># 条件删除age等于<span class="token number">18</span>的文档
POST /teacher/_delete_by_query
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;match&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
            <span class="token property">&quot;age&quot;</span><span class="token operator">:</span><span class="token number">18</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img alt="es_032" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_032.jpg" loading="lazy" class="lazy"></p> <h4 id="高级查询"><a href="#高级查询" class="header-anchor">#</a> 高级查询</h4> <h5 id="查询所有文档"><a href="#查询所有文档" class="header-anchor">#</a> 查询所有文档</h5> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;match_all&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><img alt="es_034" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_034.jpg" loading="lazy" class="lazy"></p> <h5 id="分词查询"><a href="#分词查询" class="header-anchor">#</a> 分词查询</h5> <ul><li>查看名字带有张三的数据</li></ul> <div class="language- line-numbers-mode"><pre class="language-text"><code>GET /teacher/_search
{
    &quot;query&quot;: {
        &quot;match&quot;: {
            &quot;name&quot;: &quot;zs&quot;
        }
    }
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img alt="es_033" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_033.jpg" loading="lazy" class="lazy"></p> <h5 id="字段匹配查询"><a href="#字段匹配查询" class="header-anchor">#</a> 字段匹配查询</h5> <ul><li>multi_match 与 match 类似，不同的是它可以在多个字段中查询</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code># 查询key为name和sex，value为zs的数据
GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;multi_match&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token string">&quot;zs&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;fields&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;name&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;sex&quot;</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><img alt="es_035" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_035.jpg" loading="lazy" class="lazy"></p> <h5 id="关键字查询"><a href="#关键字查询" class="header-anchor">#</a> 关键字查询</h5> <ul><li>单关键字精确查询</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;term&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                <span class="token property">&quot;value&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ls&quot;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><img alt="es_036" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_036.jpg" loading="lazy" class="lazy"></p> <ul><li>多关键字精确查询</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;terms&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;zs&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;ls&quot;</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p><img alt="es_037" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_037.jpg" loading="lazy" class="lazy"></p> <h5 id="指定字段查询"><a href="#指定字段查询" class="header-anchor">#</a> 指定字段查询</h5> <ul><li>指定查询返回的字段</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;_source&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;name&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;age&quot;</span><span class="token punctuation">]</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;terms&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;ls&quot;</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><img alt="es_038" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_038.jpg" loading="lazy" class="lazy"></p> <h5 id="过滤查询"><a href="#过滤查询" class="header-anchor">#</a> 过滤查询</h5> <ul><li><p><strong>includes</strong>：来指定想要显示的字段</p></li> <li><p><strong>excludes</strong>：来指定不想要显示的字段</p></li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;_source&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;includes&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;name&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;sex&quot;</span><span class="token punctuation">]</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span> 
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;terms&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;ls&quot;</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p><img alt="es_039" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_039.jpg" loading="lazy" class="lazy"></p> <h5 id="组合查询"><a href="#组合查询" class="header-anchor">#</a> 组合查询</h5> <ul><li><code>bool</code> 把各种其它查询通过 <code>must</code>（必须，类似 and）、<code>must_not</code>（必须不，类似 not）、<code>should</code>（应该 类似 or）的方式进行组合</li></ul> <div class="language- line-numbers-mode"><pre class="language-text"><code># 查询sex必须是男的，age不等于20的，name可以是ls的数据
GET /teacher/_search
{
    &quot;query&quot;: {
        &quot;bool&quot;: {
            &quot;must&quot;: [
                {
                    &quot;match&quot;: {
                        &quot;sex&quot;: &quot;男&quot;
                    }
                }
            ],
            &quot;must_not&quot;: [
                {
                    &quot;match&quot;: {
                        &quot;age&quot;: &quot;20&quot;
                    }
                }
            ],
            &quot;should&quot;: [
                {
                    &quot;match&quot;: {
                        &quot;name&quot;: &quot;ls&quot;
                    }
                }
            ]
        }
    }
}
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br></div></div><p><img alt="es_040" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_040.jpg" loading="lazy" class="lazy"></p> <h5 id="范围查询"><a href="#范围查询" class="header-anchor">#</a> 范围查询</h5> <ul><li>range 查询找出那些落在指定区间内的数字或者时间。range 查询允许以下字符</li></ul> <table><thead><tr><th>操作符</th> <th>说明</th></tr></thead> <tbody><tr><td>gt</td> <td>大于 &gt;</td></tr> <tr><td>gte</td> <td>大于等于 &gt;=</td></tr> <tr><td>lt</td> <td>小于 &lt;</td></tr> <tr><td>lte</td> <td>小于等于 &lt;=</td></tr></tbody></table> <div class="language-json line-numbers-mode"><pre class="language-json"><code># 查询年龄大于等于<span class="token number">18</span>，小于等于<span class="token number">25</span>的数据
GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;range&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;age&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                <span class="token property">&quot;gte&quot;</span><span class="token operator">:</span> <span class="token number">18</span><span class="token punctuation">,</span>
                <span class="token property">&quot;lte&quot;</span><span class="token operator">:</span> <span class="token number">25</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p><img alt="es_041" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_041.jpg" loading="lazy" class="lazy"></p> <h5 id="模糊查询"><a href="#模糊查询" class="header-anchor">#</a> 模糊查询</h5> <p>返回包含与搜索字词相似的字词的文档。使用的字段是 fuzzy</p> <p>编辑距离是将一个术语转换为另一个术语所需的一个字符更改的次数。这些更改可以包括：</p> <ul><li>更改字符（box → fox）</li> <li>删除字符（black → lack）</li> <li>插入字符（sic → sick）</li> <li>转置两个相邻字符（act → cat）</li></ul> <p>为了找到相似的术语，fuzzy 查询会在指定的编辑距离内创建一组搜索词的所有可能的变体或扩展。然后查询返回每个扩展的完全匹配。</p> <p>通过 fuzziness 修改编辑距离。一般使用默认值 AUTO，根据术语的长度生成编辑距离。</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;fuzzy&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                <span class="token property">&quot;value&quot;</span><span class="token operator">:</span> <span class="token string">&quot;zs&quot;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><img alt="es_042" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_042.jpg" loading="lazy" class="lazy"></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;fuzzy&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                <span class="token property">&quot;value&quot;</span><span class="token operator">:</span> <span class="token string">&quot;zs&quot;</span><span class="token punctuation">,</span>
                 <span class="token property">&quot;fuzziness&quot;</span><span class="token operator">:</span> <span class="token number">1</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p><img alt="es_043" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_043.jpg" loading="lazy" class="lazy"></p> <h5 id="多ids查询"><a href="#多ids查询" class="header-anchor">#</a> 多IDs查询</h5> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;ids&quot;</span> <span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;values&quot;</span> <span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">&quot;1&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;2&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;3&quot;</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p><img alt="es_044" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_044.jpg" loading="lazy" class="lazy"></p> <h5 id="前缀查询"><a href="#前缀查询" class="header-anchor">#</a> 前缀查询</h5> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;prefix&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                <span class="token property">&quot;value&quot;</span><span class="token operator">:</span> <span class="token string">&quot;zs&quot;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><img alt="es_045" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_045.jpg" loading="lazy" class="lazy"></p> <h5 id="字段排序"><a href="#字段排序" class="header-anchor">#</a> 字段排序</h5> <ul><li>单字段排序</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;match_all&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;sort&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span>
        <span class="token property">&quot;age&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;order&quot;</span><span class="token operator">:</span><span class="token string">&quot;asc&quot;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p><img alt="es_046" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_046.png" loading="lazy" class="lazy"></p> <ul><li>多字段排序</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
  <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;match_all&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;sort&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
      <span class="token property">&quot;age&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;order&quot;</span><span class="token operator">:</span> <span class="token string">&quot;asc&quot;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">{</span>
      <span class="token property">&quot;_score&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;order&quot;</span><span class="token operator">:</span> <span class="token string">&quot;asc&quot;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><p><img alt="es_047" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_047.jpg" loading="lazy" class="lazy"></p> <h5 id="高亮查询"><a href="#高亮查询" class="header-anchor">#</a> 高亮查询</h5> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;match&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;zs&quot;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;highlight&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;pre_tags&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&lt;font color='red'&gt;&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;post_tags&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&lt;/font&gt;&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;fields&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p><img alt="es_048" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_048.jpg" loading="lazy" class="lazy"></p> <h5 id="分页查询"><a href="#分页查询" class="header-anchor">#</a> 分页查询</h5> <ul><li><p><strong>from</strong>：当前页的起始索引，默认从 0 开始。 from = (pageNum - 1) * size</p></li> <li><p><strong>size</strong>：每页显示多少条</p></li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;query&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;match_all&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;sort&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span>
            <span class="token property">&quot;age&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                <span class="token property">&quot;order&quot;</span><span class="token operator">:</span> <span class="token string">&quot;desc&quot;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token property">&quot;from&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
    <span class="token property">&quot;size&quot;</span><span class="token operator">:</span> <span class="token number">2</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p><img alt="es_049" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_049.jpg" loading="lazy" class="lazy"></p> <h5 id="聚合查询"><a href="#聚合查询" class="header-anchor">#</a> 聚合查询</h5> <h6 id="简单聚合"><a href="#简单聚合" class="header-anchor">#</a> 简单聚合</h6> <ul><li>最大值 max</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;aggs&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;max_age&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
            <span class="token property">&quot;max&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token property">&quot;field&quot;</span><span class="token operator">:</span><span class="token string">&quot;age&quot;</span><span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;size&quot;</span><span class="token operator">:</span><span class="token number">0</span>  
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img alt="es_050" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_050.jpg" loading="lazy" class="lazy"></p> <ul><li>最小值 min</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;aggs&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;min_age&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span> 
            <span class="token property">&quot;min&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token property">&quot;field&quot;</span><span class="token operator">:</span><span class="token string">&quot;age&quot;</span><span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;size&quot;</span><span class="token operator">:</span><span class="token number">0</span> 
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img alt="es_051" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_051.jpg" loading="lazy" class="lazy"></p> <ul><li>求和 sum</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;aggs&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;sum_age&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span> 
            <span class="token property">&quot;sum&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token property">&quot;field&quot;</span><span class="token operator">:</span><span class="token string">&quot;age&quot;</span><span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;size&quot;</span><span class="token operator">:</span><span class="token number">0</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img alt="es_052" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_052.jpg" loading="lazy" class="lazy"></p> <ul><li>平均值 avg</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;aggs&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;avg_age&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span> 
            <span class="token property">&quot;avg&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token property">&quot;field&quot;</span><span class="token operator">:</span><span class="token string">&quot;age&quot;</span><span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;size&quot;</span><span class="token operator">:</span><span class="token number">0</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img alt="image-20230216152722478" data-src="C:%5CUsers%5C86138%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20230216152722478.png" loading="lazy" class="lazy"></p> <ul><li>去重之后再取总数</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;aggs&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;distinct_age&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span> 
            <span class="token property">&quot;cardinality&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token property">&quot;field&quot;</span><span class="token operator">:</span><span class="token string">&quot;age&quot;</span><span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;size&quot;</span><span class="token operator">:</span><span class="token number">0</span> 
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img alt="es_053" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_053.jpg" loading="lazy" class="lazy"></p> <ul><li>State 聚合</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;aggs&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;stats_age&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span> 
            <span class="token property">&quot;stats&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token property">&quot;field&quot;</span><span class="token operator">:</span><span class="token string">&quot;age&quot;</span><span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;size&quot;</span><span class="token operator">:</span><span class="token number">0</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><p><img alt="image-20230216153052721" data-src="C:%5CUsers%5C86138%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20230216153052721.png" loading="lazy" class="lazy"></p> <h6 id="桶聚合"><a href="#桶聚合" class="header-anchor">#</a> 桶聚合</h6> <p><strong>桶聚和相当于 sql 中的 group by 语句</strong></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code># 对age进行分组统计出现的个数
GET /teacher/_search
<span class="token punctuation">{</span>
    <span class="token property">&quot;aggs&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
        <span class="token property">&quot;age_groupby&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
            <span class="token property">&quot;terms&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token property">&quot;field&quot;</span><span class="token operator">:</span><span class="token string">&quot;age&quot;</span><span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token property">&quot;size&quot;</span><span class="token operator">:</span><span class="token number">0</span> 
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><img alt="es_055" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_055.jpg" loading="lazy" class="lazy"></p> <h2 id="es入门-映射"><a href="#es入门-映射" class="header-anchor">#</a> es入门 - 映射</h2> <h3 id="映射概念"><a href="#映射概念" class="header-anchor">#</a> 映射概念</h3> <p>映射(mapping)，类似于数据库(database)中的表结构(table)。创建数据库表需要设置字段名称，类型，长度，约束等；索引库也一样，需要知道这个类型下有哪些字段，每个字段有哪些约束信息，这就叫做映射(mapping)。</p> <h3 id="映射操作"><a href="#映射操作" class="header-anchor">#</a> 映射操作</h3> <h4 id="创建映射-put"><a href="#创建映射-put" class="header-anchor">#</a> 创建映射 - PUT</h4> <div class="language-json line-numbers-mode"><pre class="language-json"><code>PUT /order/_mapping
<span class="token punctuation">{</span>
    <span class="token property">&quot;properties&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;name&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
            <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;text&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token property">&quot;no&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
            <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;text&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token property">&quot;num&quot;</span><span class="token operator">:</span><span class="token punctuation">{</span>
            <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;keyword&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p><img alt="es_056" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_056.jpg" loading="lazy" class="lazy"></p> <p>映射数据说明：</p> <ul><li><p>字段名：任意填写，下面指定许多属性，例如：title、subtitle、images、price</p></li> <li><p>type：类型，ElasticSearch 中支持的数据类型非常丰富，说几个关键的：</p> <ul><li>String 类型，又分两种：
<ul><li>text：可分词，支持模糊查询，支持准确查询，不支持聚合查询</li> <li>keyword：不可分词，数据会作为完整字段进行匹配，支持模糊查询，支持准确查询，支持聚合查询。</li></ul></li> <li>Numerical：数值类型，分两类
<ul><li>基本数据类型：long、integer、short、byte、double、float、half_float</li> <li>浮点数的高精度类型：scaled_float</li></ul></li> <li>Date：日期类型</li> <li>Array：数组类型</li> <li>Object：对象</li></ul></li> <li><p>index：是否索引，默认为 true，也就是说你不进行任何配置，所有字段都会被索引。</p> <ul><li>true：字段会被索引，则可以用来进行搜索</li> <li>false：字段不会被索引，不能用来搜索</li></ul></li> <li><p>store：是否将数据进行独立存储，默认为 false</p> <p>原始的文本会存储在 _source 里面，默认情况下其他提取出来的字段都不是独立存储 的，是从 _source 里面提取出来的。当然你也可以独立的存储某个字段，只要设置 &quot;store&quot;: true 即可，获取独立存储的字段要比从 _source 中解析快得多，但是也会占用 更多的空间，所以要根据实际业务需求来设置。</p></li> <li><p>analyzer：分词器，这里的 ik_max_word 即使用 ik 分词器</p></li></ul> <h4 id="查看映射-get"><a href="#查看映射-get" class="header-anchor">#</a> 查看映射 - GET</h4> <div class="language-json line-numbers-mode"><pre class="language-json"><code>GET /order/_mapping
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><img alt="es_057" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_057.jpg" loading="lazy" class="lazy"></p> <h4 id="索引关联映射-put"><a href="#索引关联映射-put" class="header-anchor">#</a> 索引关联映射 - PUT</h4> <div class="language-json line-numbers-mode"><pre class="language-json"><code>PUT /order1
<span class="token punctuation">{</span>
  <span class="token property">&quot;settings&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;mappings&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;properties&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;text&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;no&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;text&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token property">&quot;num&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;keyword&quot;</span><span class="token punctuation">,</span>
        <span class="token property">&quot;index&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br></div></div><p><img alt="es_058" data-src="https://cdn.staticaly.com/gh/LiuMWork/image-hosting@master/es_md/es_058.png" loading="lazy" class="lazy"></p></div></div> <!----> <div class="page-edit"><!----> <div class="tags"><a href="/lm_blog_vdoing/tags/?tag=ElasticSearch" title="标签">#ElasticSearch</a></div> <!----></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/lm_blog_vdoing/pages/596552/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">ES入门 - 环境安装</div></a> <a href="/lm_blog_vdoing/pages/6e6e0c/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">ES入门 - 分片和副本</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/lm_blog_vdoing/pages/596552/" class="prev">ES入门 - 环境安装</a></span> <span class="next"><a href="/lm_blog_vdoing/pages/6e6e0c/">ES入门 - 分片和副本</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/lm_blog_vdoing/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/lm_blog_vdoing/pages/6d9622/"><div>
            ES进阶 - 优化配置
            <!----></div></a> <span class="date">02-20</span></dt></dl><dl><dd>02</dd> <dt><a href="/lm_blog_vdoing/pages/7e4dff/"><div>
            ES进阶 - 分片操作原理
            <!----></div></a> <span class="date">02-20</span></dt></dl><dl><dd>03</dd> <dt><a href="/lm_blog_vdoing/pages/b82771/"><div>
            ES进阶 - 并发问题
            <!----></div></a> <span class="date">02-20</span></dt></dl> <dl><dd></dd> <dt><a href="/lm_blog_vdoing/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:1512375133@qq.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://gitee.com/lmgghub/" title="gitee" target="_blank" class="iconfont icon-gitee"></a><a href="https://juejin.cn/user/2295436010326072" title="掘金" target="_blank" class="iconfont icon-juejin"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2023-2023
    <span>lm </span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div><div></div><div></div><div id="tcomment"></div><!----></div></div>
    <script src="/lm_blog_vdoing/assets/js/app.fa0e5fdd.js" defer></script><script src="/lm_blog_vdoing/assets/js/2.d9c93b35.js" defer></script><script src="/lm_blog_vdoing/assets/js/24.1688627c.js" defer></script><script src="/lm_blog_vdoing/assets/js/5.e0bc0396.js" defer></script><script src="/lm_blog_vdoing/assets/js/13.ee87d1ca.js" defer></script><script src="/lm_blog_vdoing/assets/js/14.9d4d9cf6.js" defer></script><script src="/lm_blog_vdoing/assets/js/9.fc3a629f.js" defer></script><script src="/lm_blog_vdoing/assets/js/10.4c34cde9.js" defer></script>
  </body>
</html>
